const app = getApp()
const request = require('../../../utils/https.js')
import util from '../../../utils/util.js';
var userId;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isHideToast: false,
    navList: ['收入明细', '提现明细'],
    active: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    userId = wx.getStorageSync('userId');
  },
  goGmch () {
    wx.navigateTo({
      url: '/packageB/pages/gmch/gmch',
    })
  },
  //会员介绍
  lookLevel () {
    const that = this;
    let ImgLinks = 'https://oss.km3830.cn/h5/km_webview.html';
    wx.navigateTo({
      url: '/pages/webview/webview?url=' + ImgLinks,
    })
  },
  //KM明细
  goLevel () {
    wx.navigateTo({
      url: '/packageB/pages/level/level',
    })
  },

  onWdgj () {
    //调取检测用户父级id接口，没有的话就不是通过邀请进入的用户需要绑定管家
    wx.request({
      url: getApp().Api_url + 'user/hasFather',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        userId: userId
      },
      success: (res) => {
        console.log('调取检测是否有父级===>', res.data.errMsg)
        if (res.data.errMsg == 'OK') {
          if (res.data.data == 1) { //没有管家
            console.log('没有父亲')
            wx.reLaunch({
              url: '/pages/qxzgj/qxzgj'
            })
          } else {
            wx.navigateTo({
              url: '/pages/wdgj/wdgj',
            })
          }

        }
      }
    })

  },
  //自定义弹框
  onToast () {
    const that = this;
    that.setData({
      isHideToast: true
    })
  },
  shutToast () {
    const that = this;
    that.setData({
      isHideToast: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that = this;
    userId = wx.getStorageSync('userId');

    //用户信息
    request._get(getApp().Api_url + 'user/getMainInfo', {
      userId: userId,
    }, function (res) {
      if (res.data.errMsg == 'OK') {
        console.log('****==>', res.data.data)
        let mainInfo = res.data.data;
        let className;
        if (mainInfo.rankNum == 0) {
          className = 'green';
        } else if (mainInfo.rankNum == 1) {
          className = 'pink';
        } else if (mainInfo.rankNum == 2) {
          className = 'purple';
        } else if (mainInfo.rankNum == 3) {
          className = 'golden';
        }
        that.setData({
          mainInfo: mainInfo,
          className: className,
          takeMoney: Number(mainInfo.takeMoney).toFixed(2),
          poorMoney: Number(mainInfo.rankMoney - mainInfo.takeMoney).toFixed(2)
        })

      }
    }, function () { })


    request._get(getApp().Api_url + 'rank/toAuth', {
      userId: userId
    }, function (res) {

      if (res.data.code == 200) {
        console.log('页面初始化====>', res.data.data)
        let PartnerData = res.data.data;
        let agentType = PartnerData.result; //-1无任何审核记录 0成功 1审核失败 2待审核 3审核成功
        let reason = PartnerData.reason; //失败原因
        console.log('====审核状态===>', agentType)
        that.setData({
          PartnerData: PartnerData,
          agentType: agentType
        })

      }
    }, function () { });

    //三张图片
    request._get(getApp().Api_url + 'user/memberCenter', {
      userId: userId
    }, function (res) {
      if (res.data.code == 200) {
        console.log('三张图片====>', res.data.data)
        that.setData({
          memberCenter:res.data.data
        })

      }
    }, function () { });
  },
  goVIP (e) {
    let urlId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageA/pages/VIP/VIP?urlId=' + urlId + '&url=VIP'
    })
  },
  goSVIP (e) {
    let urlId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageA/pages/VIP/VIP?urlId=' + urlId + '&url=SVIP'
    })
  },
  goAgent () {
    wx.navigateTo({
      url: '/packageB/pages/agent/agent'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})